//
//  MessageViewController.m
//  WBBaseProject
//
//  Created by 吴斌 on 2017/6/27.
//  Copyright © 2017年 吴斌. All rights reserved.
//

#import "MessageViewController.h"
#import "MessageHeadView.h"
#import "MessageTableViewCell.h"
#import "UIView+BadgeValue.h"
static NSString * const MessageTableViewCellReuseId = @"MessageTableViewCell";

@interface MessageViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) MessageHeadView *headView;
/** 图片 */
@property (nonatomic,strong) NSArray *iconIVArr;
/** title */
@property (nonatomic,strong) NSArray *titleArr;
@end

@implementation MessageViewController

#pragma mark - 生命周期 Life Circle
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.wb_leftButton.hidden = YES;
    self.navigationItem.title = @"消息中心";
    _iconIVArr = @[@"通知",@"金币",@"安全"];
    _titleArr = @[@"通知提醒",@"幸运币消息",@"账户安全"];
    [self.view addSubview:self.tableView];
    [self.tableView registerNib:[UINib nibWithNibName:MessageTableViewCellReuseId bundle:nil] forCellReuseIdentifier:MessageTableViewCellReuseId];
    [self addNavBtn];
}

- (void)addNavBtn{
    
    UIButton *right = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];
    right.titleLabel.font = [UIFont boldSystemFontOfSize:30];
    [right setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [right setTitle:@"..." forState:UIControlStateNormal];
    right.contentEdgeInsets = UIEdgeInsetsMake(-20, 0, 0, 0);
    [right addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithCustomView:right];
    self.navigationItem.rightBarButtonItem = item;
}

- (void)click
{
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return 3;
}

- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath { 
    MessageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MessageTableViewCellReuseId forIndexPath:indexPath]; 
    cell.iconIV.image = [UIImage imageNamed:_iconIVArr[indexPath.row]];
    cell.iconIV.wb_badgeValue = @"99";
    cell.titleLb.text = _titleArr[indexPath.row];
    if (indexPath.row == 2) {
        cell.lineView.hidden = YES;
    }
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10.0f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 65.0f;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath
{
}

#pragma mark - 懒加载  Lazy Load
- (UITableView *)tableView
{
    if (_tableView == nil) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - kTabbarHeight) style:UITableViewStyleGrouped];
        _tableView.backgroundColor = WB_RGBColor(245, 248, 253);
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.tableHeaderView = self.headView;
        _tableView.sectionHeaderHeight = 0.0f;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _tableView;
}

- (MessageHeadView *)headView
{
    if (_headView == nil) {
        _headView = [[MessageHeadView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 80)];
    }
    return _headView;
}

@end
